package ee.videorentalstore.protocols.commands.filmmanagercommands;

import java.util.List;

import ee.videorentalstore.protocols.commands.Command;
import ee.videorentalstore.users.UsersDatabase;
import ee.videorentalstore.users.types.Customer;

public class RegisterNewCustomerCommand extends Command
{
	private final int USER_NAME_POSITION_IN_SPLITTED_INSTRUCTIONS_LIST = 1;
	
	
	@Override
	public String getCommandDescription() 
	{
		return "REGISTER NEW CUSTOMER";	
	}
	
	
	@Override
	public void executeCommand(String inputStreamInstructionsToProcess)
	{
		List<String> splittedInstructionsList = 
				getSplittedInputStreamInstructionsToProcess(inputStreamInstructionsToProcess);
		String userName = getSpecificStringValueOutOfSplittedInstructionsList(
				splittedInstructionsList, USER_NAME_POSITION_IN_SPLITTED_INSTRUCTIONS_LIST);
		if (userName != null)
		{
			Customer newCustomer = new Customer();
			newCustomer.setUserName(userName);
			UsersDatabase.getInstance().registerANewCustomer(newCustomer);
			System.out.println("New customer has been successfully registered into the system!");
		}
		else
		{
			System.out.println("Command could not be executed due to inserted instructions errors!");
		}
	}
}
